package mbp.gui.frames;

import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import javax.swing.JTextPane;
import javax.swing.JScrollPane;


public class ContentViever extends JFrame {

	private JPanel contentPane;
	private JTextField txtType;
	private JTextPane textPane;
	private JScrollPane scrollPane;
	
	

	/**
	 * Create the frame.
	 */
	public ContentViever(String type, String content) 
	{
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblMessageType = new JLabel("Message type:");
		lblMessageType.setBounds(10, 21, 100, 14);
		contentPane.add(lblMessageType);
		
		txtType = new JTextField();
		txtType.setEditable(false);
		txtType.setText("TYPE");
		txtType.setFont(new Font("Tahoma", Font.PLAIN, 20));
		txtType.setBounds(10, 36, 240, 40);
		contentPane.add(txtType);
		txtType.setColumns(10);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 87, 422, 175);
		contentPane.add(scrollPane);
		
		textPane = new JTextPane();
		textPane.setContentType("xml");
		scrollPane.setViewportView(textPane);
		
		txtType.setText(type);
		textPane.setText(content);
		
		this.addComponentListener(new ComponentListener() {
			
			@Override
			public void componentShown(ComponentEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void componentResized(ComponentEvent arg0) {
				Component c = (Component)arg0.getSource();
				scrollPane.setSize(c.getWidth()-25, c.getHeight()-130);
				contentPane.repaint();
				contentPane.validate();
			}
			
			@Override
			public void componentMoved(ComponentEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void componentHidden(ComponentEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
